<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="icon" href="../../assets/images/favicon.ico"/>
    <title>亚诺广告有限公司</title>
    <link rel="stylesheet" href="../../assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../assets/css/login.css">
</head>
<body>
<div class="login-wrapper">
    <div class="login-header">
        <img src="../../assets/images/logo.png">亚诺广告有限公司
    </div>
    <div class="login-body">
        <div class="layui-card">
            <div class="layui-card-header">
                <i class="layui-icon layui-icon-engine"></i>&nbsp;&nbsp;用户登录
            </div>
            <form class="layui-card-body layui-form layui-form-pane" lay-filter="suFormLogin">
                <input id="vc_token" name="vc_token" type="hidden">
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-username"></i></label>
                    <div class="layui-input-block">
                        <input name="username" type="text" lay-verType="tips" lay-verify="required"
                               placeholder="账号" value="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-password"></i></label>
                    <div class="layui-input-block">
                        <input name="password" type="password" lay-verType="tips" lay-verify="required"
                               placeholder="密码" value="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-vercode"></i></label>
                    <div class="layui-input-block">
                        <div class="layui-row inline-block">
                            <div class="layui-col-xs7">
                                <input name="vc_code" type="text" lay-verType="tips" lay-verify="required"
                                       placeholder="验证码" value="" class="layui-input">
                            </div>
                            <div class="layui-col-xs5" style="padding-left: 10px;">
                                <img class="login-captcha" style="width: 110px;height: 36px;">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                <!--    <a href="javascript:;" class="layui-link pull-right">忘记密码？</a>-->
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid" lay-filter="suSubmitLogin" lay-submit>
                        登 录
                    </button>
                </div>
            </form>
        </div>
    </div>
    <div class="login-footer">
        <p>© 2024 www.anchangtu.zlact.com 版权所有</p>
        <p>© 亚诺广告有限公司 ，粤ICP备20001026号</p>
    </div>
</div>

<script type="text/javascript" src="../../assets/libs/layui/layui.js"></script>
<script>
    layui.config({
        base: '../../assets/module/'
    }).use(['form', 'setter', 'reqApi', 'admin'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var setter = layui.setter;
        var reqApi = layui.reqApi;

        // 生成随机数
        function rndNum(n) {
            var rnd = "";
            for (var i = 0; i < n; i++) {
                rnd += Math.floor(Math.random() * 10);
            }
            return rnd;
        }

        // 图形验证码
        $('.login-captcha').click(function () {
            var vc_token = rndNum(11);
            $('#vc_token').val(vc_token);
            this.src = reqApi.admin.home.verifyCode.restfulFormat({vc_token: vc_token});
        });
        $('.login-captcha').click();

        // 表单提交
        form.on('submit(suSubmitLogin)', function (data) {
            var field = data.field;
            field.grant_type = 'password';
            field.scope = 'all';
            field.auth_type = 'vc';
            field.client_id = 'think-view';
            field.client_secret = 'think-view';
            var reqEL = layer.msg('操作执行中', {icon: 16, shade: 0.01, time: 6000});
            $.ajax({
                url: reqApi.admin.home.token,
                data: field,
                type: 'POST',
                dataType: 'JSON',
                complete: function (xhr, status) {
                    layer.close(reqEL);
                },
                success: function (res) {
                    if (res && res.access_token) {
                        console.log(res.access_token)
                        setter.putToken(res.access_token);
                        setter.putParameter('lock_remind',true);
                        layer.msg('登录成功', {offset: '15px', icon: 1, time: 1000}, function () {
                            location.replace('../../');
                        });
                    }
                },
                error: function (res) {
                    $('.login-captcha').click();
                    var resMsg = '';
                    if (res && res.responseJSON && res.responseJSON.msg) {
                        resMsg = res.responseJSON.msg;
                    }
                    layer.msg(resMsg, {offset: '15px', icon: 5});
                }
            });
            return false;
        });

        // 初始化
        form.render();
    });
</script>
</body>
</html>